﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace library
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void login_button_Click(object sender, EventArgs e)
        {
            if(username.Text.Trim() == "")
            {
                MessageBox.Show("请输入用户名");
                username.Focus();
            }
            else if(password.Text.Trim() == "")
            {
                MessageBox.Show("请输入密码");
                password.Focus();
            }
            else
            {
                string sql = string.Format("select * from admininfo where username ='{0}' and password ='{1}'", username.Text.Trim(), password.Text.Trim());
                MySqlConnection conn = new MySqlConnection("server=localhost; database=librarysystem; UID=root; PWD = 123456; port = 3306");
                conn.Open();
                MySqlDataAdapter da = new MySqlDataAdapter(sql, conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                conn.Close();
                if (dt.Rows.Count > 0)
                {
                    Main frm = new Main();
                    DataRow dr = dt.Rows[0];
                    frm.adminId = dr["adminId"].ToString();
                    frm.adminName = dr["name"].ToString();
                    this.Hide();
                    frm.Show();
                }
                else
                {
                    MessageBox.Show("对不起，用户名或者密码不正确");
                }
            }
        }
    }
}
